package com.pig4cloud.pig.ds.biz_a;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.RandomUtil;
import com.pig4cloud.pig.common.biz.domain.biza.req.ACreateCommand;
import com.pig4cloud.pig.common.core.exception.CheckedException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Description : a业务逻辑校验
 * @author: lingnan
 * @date: 2023/6/19
 * @version: 1.0
 */
@Slf4j
@Service
public class BizALogicCheckChainHandler extends AbstractBizAChainHandler<ACreateCommand> {


	/**
	 * 业务处理方法
	 *
	 * @param param
	 */
	@Override
	public void handler(ACreateCommand param) {
		log.info("逻辑校验，查询参数是否合理 -> {}", param.toString());
		Assert.isTrue(queryHaveValue(param.getAc2().getCode()) - 1 > 0, () -> new CheckedException("没有足够的code！"));
	}

	private int queryHaveValue(String code) {
		return RandomUtil.randomInt(0, 3);
	}


	@Override
	public int getOrder() {
		return 10;
	}
}
